import React, { PureComponent } from 'react'
import { DatePicker } from 'antd'
import moment from "moment"
export const proDatePicker = (config) => {
  class FormatDatePicker extends PureComponent {
    onDateChange = (moment, dateString) => {
      let { onChange } = this.props;
      if (onChange) onChange(dateString);
    }
    disabledDate = current => {
      return current && current > moment().endOf('day');
    }
    render() {
      const { value, disabled} = this.props;
      return (
        <DatePicker
          picker={config.picker === 'all' ? 'date' : config.picker}
          placeholder={config.placeholder}
          showTime={config.picker === 'all'}
          onChange={this.onDateChange}
          value={value ? moment(value) : ''}
          disabled={disabled}
          disabledDate={this.disabledDate}
        />
      )
    }
  }
  return <FormatDatePicker />
}